package org.classg.edu.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.classg.edu.entity.Course;
import org.classg.edu.entity.Teacher;
import org.classg.edu.service.CourseService;
import org.classg.edu.service.TeacherService;
import org.classg.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(description = "讲师前台管理")
@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    @ApiOperation("查询所有讲师分页数据")
    @PostMapping("/queryAllTeacherPage/{current}/{limit}")
    public R queryAllTeacherPage(@ApiParam(name = "current", value = "当前页", required = true) @PathVariable Long current,
                                 @ApiParam(name = "limit", value = "每页显示记录数", required = true) @PathVariable Long limit) {
        Page<Teacher> page = new Page<>(current, limit);
        Map<String, Object> map = teacherService.queryAllTeacherPage(page);
        return R.ok().data(map);
    }

    @ApiOperation("根据讲师id查询讲师基本信息和所讲的课程")
    @GetMapping("/queryTeacherAndCourseByTeacherId/{id}")
    public R queryTeacherAndCourseByTeacherId(@ApiParam(name = "id", value = "讲师id", required = true) @PathVariable String id) {
        // 根据讲师id查询讲师基本信息
        Teacher teacher = teacherService.getById(id);
        // 根据讲师id查询讲师所讲的课程
        List<Course> courses = courseService.queryCourseByTeacherId(id);
        return R.ok().data("teacher", teacher).data("courses", courses);
    }
}
